Completed
Push — master ( 026655...6b3a87 )
by Maxence
03:26
created

settings.initFullTextSearch   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
/*
2
 * FullTextSearch - Full text search framework for Nextcloud
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2018
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: searchbar */
27
/** global: api */
28
29
var settings = {
30
31
	delay_provider: 300,
32
	delay_result: 150,
33
	resultContainer: null,
34
	entryTemplate: null,
35
	entryTemplateDefault: null,
36
	divNoResult: null,
37
38
	// 0.6.0
39
	parent: null,
40
	searchProviderId: '',
41
42
43
	/**
44
	 * generate the default template to dsplay search result entries
45
	 */
46
	generateDefaultTemplate: function () {
47
48
		var divLeft = $('<div>', {class: 'result_entry_left'});
49
		divLeft.append($('<div>', {id: 'title'}));
50
		divLeft.append($('<div>', {id: 'line1'}));
51
		divLeft.append($('<div>', {id: 'line2'}));
52
53
		var divRight = $('<div>', {class: 'result_entry_right'});
54
		divRight.append($('<div>', {id: 'score'}));
55
56
		var div = $('<div>', {class: 'result_entry_default'});
57
		div.append(divLeft);
58
		div.append(divRight);
59
60
		settings.entryTemplateDefault = $('<div>').append(div);
61
	},
62
63
64
	/**
65
	 * generate a no result display
66
	 */
67
	generateNoResultDiv: function () {
68
		var div = $('<div>', {id: 'noresult'});
69
		div.html('no result');
70
		div.hide();
71
		settings.divNoResult = div;
72
	},
73
74
75
	/**
76
	 * used to set the template to display search result entries
77
	 *
78
	 * @param template
79
	 */
80
	setEntryTemplate: function (template) {
81
		settings.entryTemplate = template;
82
	},
83
84
	/**
85
	 * used to set the container for the search result entries
86
	 *
87
	 * @param container
88
	 */
89
	setResultContainer: function (container) {
90
		settings.resultContainer = container;
91
		settings.resultContainer.prepend(settings.divNoResult);
92
	},
93
94
95
	/**
96
	 *  initialize the full text search and assign a providerId
97
	 *
98
	 * @param providerId
99
	 * @param parent
100
	 */
101
	initFullTextSearch: function (providerId, parent) {
102
		settings.searchProviderId = providerId;
103
		settings.parent = parent;
104
		searchbox.init();
0 ignored issues
show
Bug introduced by
The variable searchbox seems to be never declared. If this is a global, consider adding a /** global: searchbox */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
105
	},
106
107
108
	/**
109
	 * check that the app that call the lib contains a specific method
110
	 *
111
	 * @param method
112
	 * @returns {boolean}
113
	 */
114
	parentHasMethod: function (method) {
115
		if (settings.parent === null) {
116
			return false;
117
		}
118
		return (typeof eval('settings.parent. ' + method) === "function");
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
Coding Style Security introduced by
The use of eval is generally not recommended.

The use of eval is discouraged because it can potentially make your code vulnerable to various injection attacks.

Besides it will also prevent certain optimizations that runtimes otherwise could make.

Loading history...
119
	}
120
};
121